package com.ynet.middleground.user.service.impl;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.bean.QueryHistoryReq;
import com.ynet.middleground.user.common.ErrorMessageConstant;
import com.ynet.middleground.user.dto.EnterpriseBasicInfoHistoryDto;
import com.ynet.middleground.user.dto.QueryHistoryRecordInfoDto;
import com.ynet.middleground.user.model.QueryHistoryRecordModel;
import com.ynet.middleground.user.service.QueryHistoryRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("history")
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8", MediaType.TEXT_XML + "; " + "charset=UTF-8"})
@Api(value = "查询历史记录服务", tags = {"查询历史记录服务"})
@Service(timeout = 6000, version = "0.0.1")
public class QueryHistoryRecordServiceImpl implements QueryHistoryRecordService, GenericService {

    @Autowired
    QueryHistoryRecordModel queryHistoryRecordModel;


    @POST
    @Path("user-info")
    @ApiOperation(value = "查询用户历史信息", notes = "查询用户历史信息")
    @Override
    public ServiceResult<QueryHistoryRecordInfoDto> queryUserInfo(QueryHistoryReq requestObject) {
        ServiceResult<QueryHistoryRecordInfoDto> resultService = new ServiceResult<>();
        QueryHistoryRecordInfoDto result = null;
        try {
            result = queryHistoryRecordModel.queryUserInfo(requestObject);
        } catch (BusinessException be) {
            resultService.setError(be.getCode(), be.getMessage());
            return resultService;
        } catch (Exception e) {
            // 获取当前方法名
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "case: {}",
                    Throwables.getStackTraceAsString(e));
            resultService.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return resultService;
        }
        resultService.setResult(result);
        return resultService;
    }


    @POST
    @Path("basic-info")
    @ApiOperation(value = "查询企业用户历史信息", notes = "查询企业用户历史信息")
    @Override
	public ServiceResult<EnterpriseBasicInfoHistoryDto> queryBasicInfo(QueryHistoryReq requestObject) {
        ServiceResult<EnterpriseBasicInfoHistoryDto> resultService = new ServiceResult<>();
        EnterpriseBasicInfoHistoryDto result = null;
        try {
            result = queryHistoryRecordModel.queryBasicInfo(requestObject);
        } catch (BusinessException be) {
            resultService.setError(be.getCode(), be.getMessage());
            return resultService;
        } catch (Exception e) {
            // 获取当前方法名
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "case: {}",
                    Throwables.getStackTraceAsString(e));
            resultService.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return resultService;
        }
        resultService.setResult(result);
        return resultService;
    }
}
